﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _01.convert
{   //练习类型转换: obj.ToString(), num.ToString("x"), Convert.toInt32(o)
    //（T）a
    //a as T
    class Program
    {
        static void Main(string[] args)
        {
            int i = 123456;
            string s = "56789";
            bool b = true;
            float f = 1.23F;
            double d = 4.56D;
            long l = 213;

            string r = i.ToString("X");//16进制: x/X
            Console.WriteLine(r);
            Int32 ir = Convert.ToInt32(s); //short啦
            Console.WriteLine(ir);

            byte c = Convert.ToByte(b);
            Console.WriteLine(c);

            //看看类型
            Type t = typeof(Program);
            Console.WriteLine("t.FullName: {0}", t.FullName);
            Console.WriteLine("t.Name: {0}", t.Name);
            Console.WriteLine("t.Namespace: {0}", t.Namespace);
            Console.WriteLine("t.IsPublic: {0}", t.IsPublic);
            Console.WriteLine("t.GetMembers(): {0}", t.GetMembers());
            //Console.WriteLine("t.GetProperties(): {0}", t.GetProperties());
            Console.WriteLine("t.GetMethods(): {0}", t.GetMethods());
            Console.WriteLine("t.BaseType.FullName: {0}", t.BaseType.FullName);
            Console.WriteLine("t.IsValueType: {0}", t.IsValueType); //False


            Type t2 = typeof(Demo);
            Console.WriteLine("t2.FullName: {0}", t2.FullName);
            Console.WriteLine("t2.IsValueType: {0}", t2.IsValueType);//True 结构体是值类型！

            //
            Demo demo;
            demo.id = 1;
            demo.name = "gogogo";
            Console.WriteLine(demo.id);
            Console.WriteLine(demo.name);

            //as的用法
            object oa = "xxx";
            object ob = 123;
            string x = oa as string; //尼玛 - 这个只能转换引用类型，如果能转换，就转换，否则null。
            Console.WriteLine(x);
            string y = (string)oa;
            Console.WriteLine(y);

            //string z=ob as string;
            //Console.WriteLine(z.GetType().Name);//error!

            //as的用法
            List<int> ddd = oa as List<int>;
            Console.WriteLine(ddd == null ? "as : null" : "hehe, not null");


            Console.ReadKey();
        }
    }
    struct Demo //
    {
        public int id;
        public string name;
    }
}
